package com.jboltai.common;

import java.io.Serializable;
import java.util.Map;

/**
 * AI指定function call或者 cot思维链的结果
 */
public class AiRet implements Serializable {
    private String msg;
    private String state;
    private Object data;
    private static final String SUCCESS = "SUCCESS";
    private static final String WARN = "WARN";
    private static final String FAIL = "FAIL";

    private AiRet() {

    }

    private AiRet(String msg, boolean success) {
        this.msg = msg;
        this.state = success ? SUCCESS : FAIL;
    }
    private AiRet(String msg, boolean success, Object data) {
        this.msg = msg;
        this.state = success ? SUCCESS : FAIL;
        this.data = data;
    }

    private AiRet(String msg, boolean success, boolean warn, Object data) {
        this.msg = msg;
        this.state = success ? (warn?WARN:SUCCESS) : FAIL;
        this.data = data;
    }


    public static AiRet data(Object data) {
        return new AiRet(null, true,data);
    }
    public static AiRet data(Object data,String msg) {
        return new AiRet(msg, true,data);
    }
    public static AiRet fail(String msg) {
        return new AiRet(msg, false);
    }

    public static AiRet fail(String msg,Object data) {
        return new AiRet(msg, false,data);
    }

    public static AiRet success(String msg) {
        return new AiRet(msg, true);
    }
    public static AiRet success() {
        return new AiRet(null, true);
    }
    public static AiRet success(String msg,Object data) {
        return new AiRet(msg, true,data);
    }

    public static AiRet warn(String msg) {
        return new AiRet(msg, true,true,null);
    }
    public static AiRet warn() {
        return new AiRet(null, true,true,null);
    }
    public static AiRet warn(String msg,Object data) {
        return new AiRet(msg, true,true,data);
    }

    public static AiRet ret(Map<String,Object> ret) {
        return new AiRet(String.valueOf(ret.get("msg")),"ok".equalsIgnoreCase(String.valueOf(ret.get("state"))), ret.get("data"));
    }

    public String getMsg() {
        return msg;
    }
    public AiRet setMsg(String msg) {
        this.msg = msg;
        return this;
    }
    public boolean _isSuccess() {
        return SUCCESS.equals(state);
    }
    public boolean _isFail() {
        return FAIL.equals(state);
    }
    public boolean _isWarn() {
        return WARN.equals(state);
    }

    public String getState() {
        return state;
    }
    public Object getData() {
        return data;
    }
    public AiRet setData(Object data) {
        this.data = data;
        return this;
    }
}
